<template>
    <!-- 设计变更管理 -->
    <base-breadcrumb :title="$route.meta.title">
        <!-- 搜索 -->
        <searchData :searchData="searchArr" @search="search"></searchData>
        <!-- 表格 -->
        <a-card :bordered="false">
            <!-- <title-name :title="$route.meta.title"></title-name> -->
            <a-button class="mb12" icon="plus" type="primary" @click="handleManage(2)" v-btnPermission="'bm_034_add_01'">新增</a-button>
            <a-alert class="mb12" type="info" show-icon>
                <template slot="message">
                    <span>
                        累计发生份数：<a>{{ SummaryData.allDataNum || 0}}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        事实确认份数：<a>{{ SummaryData.factDateNum || 0 }}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                         份数确认率%：<a>{{ SummaryData.confirmRate || 0 }}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                         累计报送金额(元)：<a>{{ SummaryData.allSentMoneyCount || 0}}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>累计确认金额(元)：<a>{{ SummaryData.allConfirmMoneyCount || 0 }}</a></span>
                    <a-divider type="vertical" />
                      <span>金额确认率%：<a>{{ SummaryData.confirmMoneyRate || 0 }}</a>
                    </span>
                </template>
            </a-alert>
            <!-- 表格 -->
            <list-table
                ref="table"
                tableLayout="fixed"
                size="default"
                rowKey="id"
                :columns="columns"
                :request="loadData"
                :page-keys="['pageNo', 'pageSize','totalSize']"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
            >
            <template slot="action" slot-scope="text, record">
                     <MoreButton>
                    <a @click="handleManage(0, record,true)" v-btnPermission="'bm_027_loo_04'">查看</a>
                    <span
                        v-if="
                            record.status != 'SUBMITTED' &&
                            record.status != 'PAST' &&
                            record.status != 'ABOLISH' &&
                            record.status != 'COMMIT'
                        "
                        v-btnPermission="'bm_034_edi_02'"
                    >
                        <a @click="handleManage(1, record)">编辑</a>
                    </span>
                    <span
                        v-if=" record.status==='PAST'" v-btnPermission="'bm_034_edi_06'">
                        <a @click="handleManage(3, record)">编辑</a>
                    </span>
                    <!-- {{record}} -->
                    <span v-if="record.status == 'SUBMITTED'&&selfBtnShow(record.createUserId)&&hideBuquBtn()">
                        <a @click="handleUndo({ id: record.id, type: 3 })">撤销</a>
                    </span>
                    <span v-if="record.status == 'COMMIT'" v-btnPermission="'bm_034_tov_05'">
                        <a @click="handleInvalid({ id: record.id, type: 2 })">作废</a>
                    </span>
                    <template v-if="record.status === 'REJECTED'">
                        <template>
                            <span
                                v-if="record.status == 'DRAFT' || record.status == 'REJECTED'"
                                v-btnPermission="'bm_034_del_03'"
                            >
                                <a @click="handleRemoveParams({ id: record.id, type: 1 })">删除</a>
                            </span>
                            <span
                                v-if="
                                    record.status === 'PAST' ||
                                    record.status === 'SUBMITTED' ||
                                    record.status === 'REJECTED' ||
                                    record.status === 'ABOLISH' ||
                                    record.status === 'COMMIT'
                                "
                                v-btnPermission="'bm_034_loo_04'"
                            >
                                <approval-button :id="record.id" :status="record.status" />
                            </span>
                        </template>
                    </template>
                    <!-- 删除 -->
                    <template v-else>
                        <span
                            v-if="record.status == 'DRAFT' || record.status == 'REJECTED'"
                            v-btnPermission="'bm_034_del_03'">
                            <a @click="handleRemoveParams({ id: record.id, type: 1 })">删除</a>
                        </span>
                        <span
                            v-if="
                                record.status === 'PAST' ||
                                record.status === 'SUBMITTED' ||
                                record.status === 'REJECTED' ||
                                record.status === 'ABOLISH' ||
                                record.status === 'COMMIT'
                            "
                            v-btnPermission="'bm_034_loo_04'"
                        >
                            <approval-button :id="record.id" :status="record.status==='COMMIT'?'PAST':record.status" /> </span></template>

                     </MoreButton>
                </template>
                <template slot="status" slot-scope="text, record">
                    <list-status :status="record.status" conversion="en" :is-approval="true" :text="text" :isFile="true"/>
                </template>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import { getDesignChangeList,delDesignChange,getCountDesignChange} from '@/api/businessAffairs/designChange' // api
import BasePage from '@/views/basePage' // 基础配置
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { types,typeListApproval} from './model'
const searchArr = [
    // 搜索框
    // {name: '所属分公司', valueKey: 'branchComId', type: SelectSubCompany},
    // {name: '所属项目',keyValue: 'branchComId',valueKey: 'projectId',type: SelectProject},
    {
      name: '所属单位',
      valueKey: 'searchQuery',
      type: OrgTreeSelect,
    },
    {name: '填报时间',type: 'dateRange',value: 'modifiedTime',
        attr: {
            rangeFormat: ['createTimeBegin', 'createTimeEnd']
        }
    },
    {name: '填报人',type: 'input',value: 'fillName'},
    {name: '状态',value: 'auditStatus',type: 'select',data: typeListApproval}
]

const columns = [
    {title: '设计变更名称',dataIndex: 'name',ellipsis: true,width: 150,},
    {title: '所属分公司',dataIndex: 'branchCompanyName',ellipsis: true,width: 150,},
    {title: '所属项目',dataIndex: 'projectName',ellipsis: true,width: 150,},
    {title: '报送金额(含税)(元)',dataIndex: 'submitAndSendMoney',ellipsis: true,width: 150,},
    {title: '确认金额(含税)(元)',dataIndex: 'confirmMoney',ellipsis: true,width: 150,},
    {title: '填报人',dataIndex: 'fillName',width: 200,ellipsis: true},
    {title: '填报时间',dataIndex: 'fillTime',ellipsis: true, width: 150,},
    {title: '状态',dataIndex: 'status',scopedSlots: { customRender: 'status' },width: 150,},
    {title: '操作',dataIndex: 'action',width: '280px',align: 'center',scopedSlots: { customRender: 'action' },  fixed: 'right',}
]
export default {
    name: 'a' + Date.now(),
    extends: new BasePage(),
    components: {
        STable,
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            userId: JSON.parse(sessionStorage.getItem('ycloud-user_info')).id,
            queryParam: {}, // 查询参数
            statistics: { totalAutoContractFee: 0, totalTentativelyUpProfitFee: 0, totalTentativelyUpRate: 0 }, //统计
            loadData: async (parameter) => {
                const requestParameters = Object.assign({}, parameter, { query: this.queryParam,needCount:true});
                this.getSummaryData(requestParameters)
                return getDesignChangeList(requestParameters).then((res) => {
                 return res;
                })
            },
            removeApi: { remove: delDesignChange, invalid: delDesignChange, undo: delDesignChange },// api
            SummaryData:{
                allConfirmMoneyCount:0,   // 累计确认金额
                allDataNum:0,     //累计发生份数
                allSentMoneyCount:0,  //累计报送金额
                confirmMoneyRate:0,   // 金额确认率
                confirmRate:0,   //份数确认率
                factDateNum:0  // 事实确认份数
            }    //汇总
        }
    },
    methods: {
        // 搜索
        search(value) {
            value && (this.queryParam = value)
            if(this.queryParam.createTimeBegin && this.queryParam.createTimeEnd){
              this.queryParam.createTimeBegin = `${this.queryParam.createTimeBegin} 00:00:00`
              this.queryParam.createTimeEnd = `${this.queryParam.createTimeEnd} 00:00:00`
            }
            this.$refs.table.refresh(true)
            this.getSummaryData(this.queryParam);
        },
       async getSummaryData(requestParameters) {
        if(requestParameters.pageNo){
               let reqData = await getCountDesignChange(requestParameters);
           if(reqData.code=='200'){
            this.SummaryData = reqData.data;
           }
          }

        },
        // 操作栏
        handleManage(type, record) {
            let query = {
                editModel: type
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: 'updateDesignChange',
                query
            })
        }
    },
}
</script>
